<?php
$dp = new jDatePicker();
$dp->__dateFormat = "yy-mm-dd";
echo "<scr" . "ipt type=\"text/javascript\">";
$dp->generateDP("tanggal_dp");
echo "</scr" . "ipt>";
$dp->init();
?>

<h3 class="title-popup">Form <?php echo ($kode == "" ? "Tambah" : "Ubah"); ?> Kas Penjualan</h3>

<form action="<?php echo ($kode != "" ? $kode : ""); ?>" method="post" onsubmit="return save()" enctype="multipart/form-data">
    <?php
    if ($msg != "") {
        ?>
        <div class="BoxMessage Warning">Proses Gagal, <br /><?php echo $msg; ?></div>
        <?php
    }
    ?>

    <fieldset class="fldInput">

        <dl>
            <dt class="mandatory">Tanggal Penjualan</dt>
            <dd><input class="read-only" type="text" name="tanggal_dp" id="tanggal_dp" value="<?php echo $tanggal_dp; ?>" maxlength="10" size="10" readonly="readonly"  /></dd>

            <dt class="mandatory">Keterangan</dt>
            <dd>
                <input type="text" name="keterangan" id="keterangan" value="<?= $keterangan ?>" maxlength="100" size="100" />
            </dd>

            <dt class="mandatory">Pilih Jenis Penjualan</dt>
            <dd>
                <input class="read-only" type="text" name="nama_sjkp" id="nama_sjkp" value="<?php echo $nama_sjkp; ?>" maxlength="40" size="50" readonly="readonly"  />
                <input type="hidden" name="id_sjkp" id="id_sjkp" value="<?php echo $id_sjkp; ?>" />
                <?php echo $gbjeniskaspenjualan; ?>

            </dd>

            <dt class="mandatory">Pilih Item</dt>
            <dd>
                <input class="read-only" type="text" name="nama_item" id="nama_item" value="<?php echo $nama_item; ?>" maxlength="40" size="50" readonly="readonly"  />
                <input type="hidden" name="id_item" id="id_item" value="<?php echo $id_item; ?>" />
                <?php echo $gbitem; ?>

            </dd>

            <dt class="mandatory">Jumlah</dt>
            <dd><input type="text" name="quantity_dp" id="quantity_dp" value="<?php echo $quantity_dp; ?>" maxlength="40" size="35"  /></dd>

            <dt class="mandatory">Currency</dt>
            <dd>
                <select id="currency" name="currency" value="<?php echo $using_dollar_currency; ?>" style="width: 20%;">
                    <option value="Rp" selected>Rupiah</option>
                </select>
            </dd>

            <dt>Diskon</dt>
            <dd><input type="text" name="diskon_dp" id="diskon_dp" value="<?php echo $diskon_dp; ?>" maxlength="40" size="35"  /></dd>


            <dt>&nbsp;</dt>
            <dd>
                <ul id="note">
                    <li>Field dengan remark harus diisi.</li>
                    <li>Gunakan tombol Cari untuk field dengan property read-only.</li>
                </ul>

            </dd>

        </dl>
    </fieldset>
    <div id="box-control-save">
        <input type="hidden" name="vSave" id="vSave" value="1" />
        <input type="hidden" name="kode" id="kode" value="<?php echo $kode ?>" />
        <input type="hidden" name="vMode" value="<?php echo ($kode == "" ? "add" : "edit"); ?>" />
        <input type="submit" class="CommandButton" name="btnSimpan" value="Save" />&nbsp;
        <input type="button" class="CommandButton" value="Cancel" onclick="javascript:closeGB_();"/>
    </div>
</form>
<script type="text/javascript">
    /*window.parent.parent.GB_hide();window.parent.parent.location.reload()*/
    function closeGB_() {
<?php echo CloseGB(true); ?>
    }
    function save() {
        var mandatory = ["tanggal_dp", "id_sjkp", "id_item", "quantity_dp", "currency"];
        var mandatoryName = ["Tanggal", "Jenis", "Item", "Jumlah", "Currency"];

        for (var i = 0; i < mandatory.length; i++) {

            if (trimValue(document.getElementById(mandatory[i]).value) == '') {
                alert('Parameter ' + mandatoryName[i] + ' Penjualan tidak boleh kosong!');
                return false;
            }
        }

        return true;
    }

    function trimValue(str) {
        var out = "";
        out = str.replace(/^\s+|\s+$/g, "");
        return out;
    }

    function _obj_fSendValue(kode, nama, elmKode, elmNama) {
        var elmk = document.getElementById("" + elmKode + "");
        var elmn = document.getElementById("" + elmNama + "");
        try {
            elmk.value = kode;
            elmn.value = nama;
        }
        catch (e) {
            alert(e.message);
        }
    }



</script>
